package com.aplink.generic.xmlparser;

import org.w3c.dom.Node;

import android.text.TextUtils;

import com.aplink.generic.pojo.controlspec.SwitchSpec;

public class SwitchParser {
	public static final String DISABLE_GROUP = "disableGroup";
	public static final String TEXT_OFF = "textOff";
	public static final String TEXT_ON = "textOn";
	public static final String VALUE_OFF = "valueOff";
	public static final String VALUE_ON = "valueOn";

	public static SwitchSpec parse(final Node node) {
		final SwitchSpec switchSpec = new SwitchSpec();
		if (node.hasAttributes()) {
			String value = XmlPaserUtil.getAttrValue(node,
			        SwitchParser.VALUE_ON);
			if (!TextUtils.isEmpty(value)) {
				switchSpec.setValueOn(value);
			}

			value = XmlPaserUtil.getAttrValue(node, SwitchParser.VALUE_OFF);
			if (!TextUtils.isEmpty(value)) {
				switchSpec.setValueOff(value);
			}
			value = XmlPaserUtil.getAttrValue(node, SwitchParser.TEXT_ON);
			if (!TextUtils.isEmpty(value)) {
				switchSpec.setTextOn(value);
			}

			value = XmlPaserUtil.getAttrValue(node, SwitchParser.TEXT_OFF);
			if (!TextUtils.isEmpty(value)) {
				switchSpec.setTextOff(value);
			}
			value = XmlPaserUtil.getAttrValue(node, SwitchParser.DISABLE_GROUP);
			if (!TextUtils.isEmpty(value)) {
				switchSpec.setDisableGroupID(value);
			}
		}
		return switchSpec;
	}
}
